<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:bm="livcos.org/ns/bm"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="doc bm">
  
  <xsl:decimal-format grouping-separator="'"/>
  <xsl:variable name="currency-picture">#'###.00</xsl:variable>

  <xsl:template match="bm:forecast">
    <tr id="{@id}">
      <td>
        <xsl:value-of select="@year" />
      </td>
      <td align="right">
        <xsl:value-of select="format-number(sum(bm:revenue/@amount), $currency-picture)" />
      </td>
      <td align="right">
        <xsl:value-of select="format-number(sum(bm:expense/@amount), $currency-picture)" />
      </td>
      <td>
        <xsl:apply-templates select="bm:body-count" />
      </td>
    </tr>
  </xsl:template>
  
  <xsl:template match="bm:body-count">
    <xsl:if test="position() > 1">, </xsl:if>
    <span id="{@id}"><xsl:value-of select="@position"/>: <xsl:value-of select="@count"/></span>
  </xsl:template>
  
  <xsl:template match="bm:forecast[bm:forecast]">
    <div id="{@id}" class="table">
      <table border="1" cellpadding="4" cellspacing="0">
        <tr>
          <th>Year</th>
          <th>Revenue</th>
          <th>Expenses</th>
          <th>Body Count</th>
        </tr>
        <xsl:apply-templates select="bm:forecast" />
    <!-- tr style="font-style: italic;">
      <td>&#160;</td>
      <td align="right">
        <xsl:value-of select="format-number(sum(bm:forecast/bm:revenue/@amount), $currency-picture)" />
      </td>
      <td align="right">
        <xsl:value-of select="format-number(sum(bm:forecast/bm:expense/@amount), $currency-picture)" />
      </td>
      <td>&#160;</td>
    </tr-->
      </table>
    </div>
  </xsl:template>
  
</xsl:stylesheet>
